<?php
namespace App\Services;

use EasyWeChat\Factory;

/**
 * Created by PhpStorm.
 * User: liuta
 * Date: 2018/9/29
 * Time: 18:44
 */


class WechatService
{
    /**
     * @param $options
     * @return \EasyWeChat\OfficialAccount\Application
     */
    public static function getApp($options = [])
    {
        $config = [
            'app_id' => config('wechat.app_id'),
            'secret' => config('wechat.app_secret'),

            // 指定 API 调用返回结果的类型：array(default)/collection/object/raw/自定义类名
            'response_type' => 'array',

            'log' => [
                'default' => 'wechat-oa',
            ],
        ];
        if ($options) {
            $config = array_merge($config, $options);
        }

        return Factory::officialAccount($config);
    }


    /**
     * @return \EasyWeChat\Payment\Application
     */
    public static function getPayment()
    {
        $config = [
            'app_id' => config('wechat.app_id'),
            'mch_id' => config('wechat.app_mch_id'),
            'key' => config('wechat.app_mch_key'),
            // XXX: 绝对路径！！！
            'cert_path' => config('wechat.app_mch_cert_path'),
            'key_path' => config('wechat.app_mch_key_path'),

            'notify_url' => route('api.notifies.wechatpay'),
            // 'device_info'     => '013467007045764',
            // 'sub_app_id'      => '',
            // 'sub_merchant_id' => '',
            // ...
        ];

        return Factory::payment($config);
    }

}
